package com.szholly.utils.util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

/*
 * ����properties�ļ��Ķ�д������
 */
public class PropertiesUtils {

	private static Properties file = new Properties(); 
	private String fileName;

	/*
	 * ��ʼ���ļ�
	 */
	public void iniFile(String fileName){
		this.fileName=fileName;
		InputStream inputStream = getClass().getResourceAsStream("/"+fileName);
		if(inputStream==null){
			System.out.println(fileName+" ������!");
		}
		else{
			try {
				file.load(inputStream);
				inputStream.close();
			} catch(IOException e) {
				e.printStackTrace();
				throw new RuntimeException(e.getMessage());
			}
		}
	}

	/*
	 * ������
	 */
	public String read(String propertyName){
		return  file.getProperty(propertyName);
	}
	
	/*
	 * д����
	 */
	public void write(String name,String value){
		file.setProperty(name, value);
	}

	/**
	 * �ر��ļ�
	 */
	public void save(){
		try {
			OutputStream os=new FileOutputStream(fileName);
			file.store(os, null);
			os.close();
		}catch (Exception e) {
			e.printStackTrace();
			System.out.println(fileName+"�޷���ر�");
			throw new RuntimeException(e.getMessage());
		}
	}
}
